import requests
import sys
import re
import jieba
import os
import codecs
from ResumeParsing import ResumeParsing
import datetime
#r = requests.post("http://127.0.0.1:5000/register", data=user_info)
from win32com import client as wc

# with open(sys.path[0] + '/51job_叶其焕(116660937).doc', encoding='gb18030') as fobj:
#     content1 = fobj.read()
# with open(sys.path[0] + '/51job_叶其焕(116660937).doc', 'w', encoding='utf-8') as fobj:
#     fobj.write(content1)
mulu='C:/Users/Vinecheck/Desktop/5-15/寒武管培生/简历咖/'
# htmlfile = codecs.open('ianli.htm','r',encoding='gb18030')
# content=htmlfile.read()
# print(content)
# result=[]
# parser = ResumeParsing(htmlfile)
# jianlitype = ''
# try:
#     jianlitype = parser.DefineFiletype()
# except Exception:
#     print('简历类型错误')
# print(jianlitype)
# if (jianlitype == 'zhiliandoc'):
#     result = parser.zhiliandoc(htmlfile)
# elif (jianlitype == 'zhilianhtm'):
#     result = parser.zhilianhtm(htmlfile)
# elif (jianlitype == 'pin101'):
#     result = parser.pin101(htmlfile)
# elif (jianlitype == 'job51'):
#     result = parser.job51(htmlfile)
# elif (jianlitype == 'rencaia'):
#     result = parser.rencaia(htmlfile)
# elif (jianlitype == 'jianlika'):
#     result = parser.jianlika(htmlfile)
# elif (jianlitype == 'fenjianli'):
#     result = parser.fenjianli(htmlfile)
# elif (jianlitype == 'zhuopin'):
#     result = parser.zhuopin(htmlfile)
# print(result)
# htmlfile1 = codecs.open('ianli.htm','r',encoding='gb18030')
# files = {'file': htmlfile1}
# r1 = requests.post("http://192.168.0.110:8080/register", files=files)
# print(r1.text)
# print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
txtt=[]
# adminlist=pd.DataFrame(columns=['更新日期','姓名','性别','年龄','手机号','邮箱','学历','婚姻','所在地','学校','专业','最近工作职位','期望工作地点','期望薪资','工作年限'])

namefile=[]
for files in os.listdir(mulu):
    namefile.append(files)
for name in namefile:
     if re.findall('.*?\.txt',name)!=[]  or re.findall('.*?\.htm',name)!=[] or re.findall('.*?\.doc',name)!=[]:
        txtt.append(name)
l=len(txtt)
print(l)
for j in range(0,l):
    print(txtt[j])
    starttime1 = datetime.datetime.now()
    try:
        htmlfile = codecs.open(mulu+txtt[j],'r',encoding='utf-8')
        files = {'file': htmlfile}
        # r = requests.post("http://118.190.210.44:8087/register", files=files)
        r = requests.post("http://192.168.0.110:8087/register", files=files)
    except UnicodeDecodeError:
        print("gbk编码格式")
        htmlfile = codecs.open(mulu + txtt[j], 'r', encoding='gb18030')
        files = {'file': htmlfile}
        # r = requests.post("http://118.190.210.44:8087/register", files=files)
        r = requests.post("http://192.168.0.110:8087/register", files=files)
    print("运行时间")
    endtime1 = datetime.datetime.now()
    print((endtime1 - starttime1))
    print(r.text)
    print('###########################################3')
